package com.ourteam.education.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ourteam.education.dao.LessonDAOQueryBean;
import com.ourteam.education.domain.LessonBean;
import com.ourteam.education.service.ILessonManageService;
import com.ourteam.frame.controller.AbstractCRUDServiceController;

@Controller
@CrossOrigin
@RequestMapping("/api/EDUCATION/lesson")
public class LessonManageAPI extends AbstractCRUDServiceController<LessonDAOQueryBean, LessonSearchBean, LessonBean> {

	@Autowired
	private ILessonManageService lessonService;

	@Override
	protected LessonDAOQueryBean newQueryBean() {
		return new LessonDAOQueryBean();
	}

	@Override
	protected int queryCount(LessonDAOQueryBean queryBean) throws Exception {
		return lessonService.queryLessonCount(queryBean);
	}

	@Override
	protected LessonBean[] queryData(LessonDAOQueryBean queryBean) throws Exception {
		return lessonService.queryLessons(queryBean);
	}

	@Override
	protected void deleteData(long[] ids) throws Exception {

		lessonService.deleteLessons(ids);

	}

	@Override
	protected LessonBean getDataById(long id) throws Exception {
		return lessonService.getLessonById(id);
	}

	@Override
	protected void saveData(LessonBean dataBean) throws Exception {

		if (dataBean.getId() != 0) {
			lessonService.modifyLesson(dataBean);
		} else {
			lessonService.addNewLesson(dataBean);
		}

	}

}
